<template>
  <div class="integral-detail" v-if="list">
    <Scroll class="detail-scroll" v-if="list.length">
      <div class="integral-list">
        <div class="list-item" v-for="(item, index) of list" :key="index">
          <div class="left">
            <div class="dot" :class="{'add': item.score > 0 ? true : false, 'reduce': item.score < 0 ? true : false }"></div>
            <div class="info">
              <div class="title">{{item.record}}</div>
              <div class="time">{{item.created_at.split(' ')[0]}}</div>
            </div>
          </div>
          <div
            class="right"
            :class="{'add': item.score > 0 ? true : false, 'reduce': item.score < 0 ? true : false }"
          >{{item.score > 0 ? '+' + item.score :  item.score}}积分</div>
        </div>
      </div>
    </Scroll>
    <no-result v-else :src="require('@/assets/images/2-zwnr.png')" msg="暂无积分明细" />
  </div>
</template>
<script>
import Scroll from '@/components/scroll/scroll'
import NoResult from '@/components/no-result/no-result'
import { getIntegralDetail } from '@/api/my'
const ERR_OK = 200
export default {
  components: {
    Scroll,
    NoResult
  },
  data () {
    return {
      list: null
    }
  },
  created () {
    this._getIntegralDetail()
  },
  methods: {
    _getIntegralDetail () {
      getIntegralDetail()
        .then(res => {
          if (res.code === ERR_OK) {
            console.log(res)
            this.list = res.data
          }
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.integral-detail {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  background: #fff;
  touch-action: none;
  padding: 0 0.36rem;
  box-sizing: border-box;
  .detail-scroll {
    width: 100%;
    height: 100%;
  }
  .integral-list {
    .list-item {
      width: 100%;
      border-bottom: 1px solid rgba(0, 4, 0, 0.3);
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0.61rem 0 0.31rem 0;
      &:last-of-type {
        border-bottom: none;
      }
      .left {
        display: flex;
        .dot {
          width: 0.12rem;
          height: 0.12rem;
          border-radius: 50%;
          margin-right: 0.45rem;
          margin-top: 0.1rem;
          &.add {
            background: rgba(0, 4, 0, 1);
          }
          &.reduce {
            background: #999999;
          }
        }
        .info {
          .title {
            font-size: 0.28rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(0, 4, 0, 1);
          }
          .time {
            font-size: 0.22rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(102, 102, 102, 1);
            margin-top: 0.25rem;
          }
        }
      }
      .right {
        font-size: 0.22rem;
        font-family: PingFang SC;
        font-weight: 400;
        &.add {
          color: rgba(0, 4, 0, 1);
        }
        &.reduce {
          color: rgba(190, 190, 190, 1);
        }
      }
    }
  }
}
</style>
